//
//  EColumViewController.m
//  chanlin
//
//  Created by Ryan on 15-2-12.
//  Copyright (c) 2015年 chanlin. All rights reserved.
//

#import "EColumViewController.h"
#import "IFCoreDataManager.h"
#import "EColumn.h"

@interface EColumViewController ()

@property (nonatomic,strong) UIButton *toolView;

@end

@implementation EColumViewController

- (void)viewDidLoad {
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.tableView.frame=CGRectMake(0, 20.f, GlobleWidth, GlobleHeight-20.f-44.f);
    [self.tableView hiddenBottom:YES];
    [self.tableView hiddenHead];
    [self loadbackview];
    
    NSDictionary *dic=self.dic;
    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES];
    NSFetchRequest *req = [[NSFetchRequest alloc] initWithEntityName:@"EColumn"];
    req.predicate = [NSPredicate predicateWithFormat:@"num=%@", [dic sgrGetStringForKey:@"num"]];
    req.sortDescriptors = @[sort];
    self.fetch = [[NSFetchedResultsController alloc] initWithFetchRequest:req
                                                     managedObjectContext:[IFCoreDataManager sharedInstance].mainMoc
                                                       sectionNameKeyPath:nil
                                                                cacheName:nil];
    self.fetch.delegate=self;
    [self.fetch performFetch:nil];
    
    
    
    if([self isViewLoaded])
        [self reloadTable];

    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     EColumn *colum=[self.fetch objectAtIndexPath:indexPath];
    return _isStrNotNull(colum.name)?44.f:0.f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EColumn *colum=[self.fetch objectAtIndexPath:indexPath];
    UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.selectionStyle=UITableViewCellSelectionStyleGray;
    
    if(_isStrNotNull(colum.name)){
    
    UILabel *label=[[UILabel alloc] init];
   
    label.textColor=RGB(0x84,0x92,0xa7);
        label.font=[UIFont systemFontOfSize: 17.f];
    label.text=colum.name;
    label.frame=CGRectMake(13.f, 0.f, GlobleWidth-30.f, 44.f);
    [cell.contentView addSubview:label];
    
    CALayer *cellSeperatorImgView=[CALayer layer];
    cellSeperatorImgView.frame=CGRectMake(0, 0.f, GlobleWidth, 0.5f);
    cellSeperatorImgView.backgroundColor=RGB(0xe0, 0xe0, 0xde).CGColor;
    [cell.contentView.layer addSublayer:cellSeperatorImgView];
    }
//
//
//    cellSeperatorImgView=[CALayer layer];
//    cellSeperatorImgView.frame=CGRectMake(0, colum.cHeight-0.5f, GlobleWidth, 0.5f);
//    cellSeperatorImgView.backgroundColor=RGB(0xe0, 0xe0, 0xde).CGColor;
//    [cell.layer addSublayer:cellSeperatorImgView];

    
    return cell;
}

- (void)loadbackview{
    self.toolView=[UIButton buttonWithType:UIButtonTypeCustom];
    self.toolView.frame=CGRectMake(GlobleWidth-56.0f, GlobleHeight-44.0f, 56.0f, 44.0f);
    // self.toolView.backgroundColor=[UIColor orangeColor];
    [self.toolView setImage:[UIImage imageNamed:@"order_back.png"] forState:UIControlStateNormal];
    //    [self.toolView setImage:sgrUIImageFile(ICurrentTheme.orderStyle.orderbackName2) forState:UIControlStateHighlighted];
    [self.toolView addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.toolView];
}

- (void)back{
    // [[IfengOrderStore sharedInstance] setOrderMenuItem:self.theOrdered];
    //    [[NSNotificationCenter defaultCenter] postNotificationName:IfengChangeNewsMenuNotification object:nil];
    [self.dispatchObj pop];
    // [DispatchCenter pop];
}



@end
